package com.android.takegism.service;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

import com.android.takegism.R;
import com.android.takegism.ui.SolvePuzzleActivity;

public class PuzzleService extends Service {
    private int id = 123;
    private String channelId = "com.android.takagism.service.PuzzleService";
    private Bundle bundle;


    public class PuzzleBinder extends Binder{

        public Bundle getBundle() {
            return bundle;
        }
    }
    public PuzzleService() {
    }

    PuzzleBinder binder = new PuzzleBinder();


    @Override
    public void onCreate() {
        Log.d("ZZJ","启动");
        NotificationChannel channel = new NotificationChannel(channelId, "Channel 1", NotificationManager.IMPORTANCE_DEFAULT);
        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        manager.createNotificationChannel(channel);
        Notification.Builder builder = new Notification.Builder(this, channel.getId());
        Intent intent = new Intent(this, SolvePuzzleActivity.class);
        bundle = new Bundle();
        bundle.putString("clue","钟智杰牛逼");
        intent.putExtras(bundle);

        System.out.println(binder.toString());
        builder
                .setContentIntent(PendingIntent.getActivity(this,0,intent,0))
                .setAutoCancel(true)
                .setTicker("正在接受数据，请勿关闭，否则可能影响游戏体验")
                .setContentText("正在接受数据...")
                .setContentTitle("传感器")
                .setSmallIcon(R.mipmap.ic_launcher_round)
                .setWhen(System.currentTimeMillis())
        ;
//        startForeground(id,builder.build());
        manager.notify(id,builder.build());
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent){
        System.out.println(intent);
        System.out.println(intent);
        System.out.println(intent);
        return binder;
    }

    @Override
    public boolean onUnbind(Intent intent) {

        return super.onUnbind(intent);
    }
}